package io.github.talelin.latticy.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.github.talelin.latticy.mapper.AswTypeMapper;
import io.github.talelin.latticy.model.AswTypeDO;
import io.github.talelin.latticy.service.AswTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 题目分类表 服务实现类
 * </p>
 *
 * @author generator@tomingto
 * @since 2021-06-02
 */
@Service
public class AswTypeServiceImpl extends ServiceImpl<AswTypeMapper, AswTypeDO> implements AswTypeService {

    @Autowired
    private AswTypeMapper aswTypeMapper;
    @Override
    public List<AswTypeDO> findAll() {
        return aswTypeMapper.selectList(null);
    }

    public Integer updateTypeState(Integer aswTypeState,Integer id){
        return aswTypeMapper.updateTypeState(aswTypeState,id);
    }

    public boolean updateType(AswTypeDO aswTypeDO, Map<String,Object> map){
        aswTypeDO.setAswTypeName(map.get("asw_type_name").toString());
        aswTypeDO.setAswTypeImg(map.get("asw_type_img").toString());
        aswTypeDO.setAswTypeSort(Integer.parseInt(map.get("asw_type_sort").toString()));
        return aswTypeMapper.updateById(aswTypeDO)>0;
    };

    public  boolean createType(Map<String,Object> map){
        AswTypeDO aswTypeDO = new AswTypeDO();
        aswTypeDO.setAswTypeName(map.get("asw_type_name").toString());
        aswTypeDO.setAswTypeImg(map.get("asw_type_img").toString());
        aswTypeDO.setAswTypeSort(Integer.parseInt(map.get("asw_type_sort").toString()));
        return aswTypeMapper.insert(aswTypeDO)>0;
    }

    public AswTypeDO getById(Integer id){
        AswTypeDO aswTypeDO = aswTypeMapper.selectById(id);
        return aswTypeDO;
    }

    public boolean deleteById(Integer id){
        return aswTypeMapper.deleteById(id)>0;
    };
}
